//Created by MyEclipse Struts
// XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_4.1.1/xslt/JavaClass.xsl

package test.struts.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import test.app.dto.ContenidoDTO;


public class LoginAction extends Action
{
	/*
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {
        String u=request.getParameter("usuario");
        String p=request.getParameter("clave");
        
        if( u.equals(p) && !u.equals("") )
        {
            return mapping.findForward("bien");
        }
        else
        {
        	sendErrorMessage(request, "login.error" );
        	
        	form.reset(mapping, request);
        	
            return mapping.getInputForward();
        }
    }
    */
	
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {
		ApplicationContext ctx =  WebApplicationContextUtils.getRequiredWebApplicationContext(servlet.getServletContext());
		
		ContenidoDTO c = (ContenidoDTO) ctx.getBean("conte");
		
		System.out.println("TITULO: " + c.getTitulo() );
		
        return mapping.getInputForward();
    }
	
	/**
	 * Helper method para envios de mensages de error globales al usuario sin parametros
	 * 
	 * @param request
	 * @param msg
	 */
	protected void sendErrorMessage(HttpServletRequest request, String msg) 
	{
		ActionMessages messages = new ActionMessages();
		messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(msg));
		saveErrors(request, messages);
	}
	
    public Object getBean(String name) 
    {
        ApplicationContext ctx =  WebApplicationContextUtils.getRequiredWebApplicationContext(servlet.getServletContext());
        return ctx.getBean(name);
    }

}
